package cn.hd.commonService.exception;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class CustomException extends RuntimeException {

    /**
     * 错误码
     */
    protected Integer errorCode =500;
    /**
     * 错误信息
     */
    protected String errorMsg;

    public CustomException(String errorMsg) {
        this.errorMsg = errorMsg;
    }
    /**
     * @CreatedBy dsl
     * 将customException转化为exception
     */
    public static  Exception cloneCustomException(CustomException e){
        return new Exception(e.getErrorMsg(),e);
    }

    public static CustomException cloneException(Exception e){
        try {
            return (CustomException) e;
        }catch (ClassCastException exception){
            return new CustomException(e.getMessage());
        }
    }

}
